home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3977 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.7 KB  |  65 lines

  1. Newsgroups: comp.lang.c
  2. Path: news.ner.bbnplanet.net!daprez!panther!otisg
  3. From: otisg@panther.middlebury.edu (Otis Gospodnetic)
  4. Subject: simple code, argc, argv, strcmp()
  5. Message-ID: <11f7cc$17261a.3b3@daprez>
  6. Date: Thu, 01 Feb 1996 04:38:26 GMT
  7. Keywords: strcmp encode decode argc argv
  8. X-Newsreader: TIN [version 1.2 PL2]
  9.  
  10. Hi, a C question...
  11. this one has been bothering ALL afternoon !
  12.  
  13. This snippet of code is supposed to call appropriate function based on what
  14. command line arguments are supplied.
  15.  
  16. usage: <program> -e [SourceFile] RemoteFile
  17.         or
  18.        <program> -d [InFile]
  19.  
  20. if the person doesn't use this right the program is supposed to call Usage()
  21. which is not here, but it's in my code, and if the person calls the program
  22. the correct way one of the two actions should be taken (encode or decode).
  23.  
  24. Problem - I am doing something wrong and I almost always end up calling
  25. Usage() even if I use the program correctly.
  26.  
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include <string.h>
  30.  
  31. int main (int argc, char **argv) {
  32.  
  33.   void Usage   (void);
  34.   void Encode (int, char **);
  35.   void Decode (int, char **);
  36.  
  37.   if (!strcmp(argv[1],"-d") || !strcmp(argv[1],"-e")) {
  38.     Usage();
  39.   }
  40.   if (strcmp(argv[1],"-d") && argc < 3) {
  41.     printf ("D %i\n", argc);
  42.     Usage();
  43.   }
  44.   if (strcmp(argv[1],"-e") && argc < 4) {
  45.     printf ("E %i\n", argc);
  46.     Usage();
  47.   }
  48.   if (strcmp(argv[1],"-d") && argc == 3) {
  49.     Decode(argc, argv);
  50.   }
  51.   if (strcmp(argv[1],"-e") && argc == 4) {
  52.     Encode(argc, argv);
  53.   }
  54.   return 0;
  55. }
  56.  
  57. Can someone see what's wrong with this ?
  58. am I not using strcmp() right ?
  59.  
  60. Thanks a bunch (I don't have any more hair to pull from my head !)
  61.  
  62. Otis
  63. Otis.Gospodnetic@mail.middlebury.edu
  64.  
  65.